package com.appwoo.txtws.service;

import android.app.ActivityManager;
import android.app.ActivityManager.RunningTaskInfo;
import android.app.KeyguardManager;
import android.app.KeyguardManager.KeyguardLock;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import com.appwoo.android.exception.NotFoundNetWorkException;
import com.appwoo.android.exception.TimeOutException;
import com.appwoo.txtws.activity.ScreenOffActivity;
import com.appwoo.txtws.bean.ServerAppBean;
import com.appwoo.txtws.bean.StateBean;
import com.appwoo.txtws.component.DBHelper;
import com.appwoo.txtws.component.Global;
import com.appwoo.txtws.component.Logger;
import com.appwoo.txtws.component.RqSP;
import com.appwoo.txtws.component.VolumeCtrl;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import org.xmlpull.v1.XmlPullParserException;

public class RQScreenLock
{
  private static String time = null;
  private String alertString;
  private Context context = null;
  private SharedPreferences.Editor editor;
  private SharedPreferences.Editor editorl = null;
  private boolean isGaoJi = false;
  private boolean isShiDuan = false;
  private boolean isSumTime;
  private SharedPreferences isUseSp;
  private LoginService loginService = new LoginService();
  KeyguardManager.KeyguardLock mKeyguardLock = null;
  KeyguardManager mKeyguardManager = null;
  private Integer n = Integer.valueOf(0);
  private RQNetLock rnl;
  ServerAppBean serverAppBean;
  private SharedPreferences sp;
  private SharedPreferences spl = null;
  private String todayRule = "";
  private String todayScreen = "2";
  private SharedPreferences webControlSP;

  public RQScreenLock(Context paramContext)
  {
    this.context = paramContext;
    this.serverAppBean = ((ServerAppBean)this.context.getApplicationContext());
    if (this.serverAppBean.mKeyguardLock == null)
    {
      Logger.i("tj", "null   mKeyguardLock  新建");
      this.mKeyguardManager = ((KeyguardManager)this.context.getSystemService("keyguard"));
      this.mKeyguardLock = this.mKeyguardManager.newKeyguardLock("");
      this.serverAppBean.mKeyguardLock = this.mKeyguardLock;
    }
    this.sp = this.context.getSharedPreferences("ScreenLock", 0);
    this.editor = this.sp.edit();
    this.todayScreen = this.sp.getString("todayScreen", "2");
    this.webControlSP = this.context.getSharedPreferences("web_time_control", 0);
    this.isUseSp = this.context.getSharedPreferences("timeconfig" + Global.getTodayDate(this.context), 0);
    this.isSumTime = this.isUseSp.getBoolean("shichang", false);
    this.isShiDuan = this.isUseSp.getBoolean("shiduan", false);
    this.isGaoJi = this.isUseSp.getBoolean("gaoji", false);
    Logger.d("tag", "isSumTime=" + this.isSumTime + "\nisShiDuan=" + this.isShiDuan + "\nisGaoJi=" + this.isGaoJi);
    this.rnl = new RQNetLock(paramContext);
  }

  private boolean isTopActivity()
  {
    String str = ((ActivityManager.RunningTaskInfo)((ActivityManager)this.context.getSystemService("activity")).getRunningTasks(1).get(0)).topActivity.getClassName();
    return (str.endsWith("com.appwoo.txtws.activity.EmergencyDialogActivity")) || (str.endsWith("com.appwoo.txtws.activity.ScreenOffActivity")) || (str.endsWith("com.appwoo.txtws.activity.UpdateActivity")) || (str.endsWith("com.appwoo.txtws.activity.DirectionActivity")) || (str.endsWith("com.appwoo.txtws.activity.GuideActivity")) || (str.endsWith("com.android.packageinstaller.PackageInstallerActivity")) || (str.endsWith("com.android.settings.DeviceAdminAdd"));
  }

  public void LockScreenCmd(String paramString)
  {
    if (this.sp == null)
      this.sp = this.context.getSharedPreferences("ScreenLock", 0);
    if (this.editor == null)
      this.editor = this.sp.edit();
    String str = this.sp.getString("LockTime", "2011-11-11 11:11:11");
    if (this.sp.getString("ScreenCmd", "2").equals("2"))
      try
      {
        if (t1BeforeT2(str, paramString, "0"))
          if (Global.mode == 1)
          {
            if ((Global.inHoliday == 0) && (Global.inLeave == 0))
            {
              this.editor.putString("LockTime", paramString);
              this.editor.putString("ScreenCmd", "0");
              this.editor.commit();
            }
          }
          else if (Global.mode == 0)
          {
            this.editor.putString("LockTime", paramString);
            this.editor.putString("ScreenCmd", "0");
            this.editor.commit();
            return;
          }
      }
      catch (Exception localException)
      {
      }
  }

  public void UnlockScreenCmd(String paramString)
  {
    if (this.sp == null)
      this.sp = this.context.getSharedPreferences("ScreenLock", 0);
    if (this.editor == null)
      this.editor = this.sp.edit();
    String str = this.sp.getString("LockTime", "2011-11-11 11:11:11");
    if (this.sp.getString("ScreenCmd", "2").equals("0"));
    try
    {
      if (t1BeforeT2(str, paramString, "2"))
      {
        this.editor.putString("LockTime", paramString);
        this.editor.putString("ScreenCmd", "2");
        this.editor.commit();
      }
      return;
    }
    catch (Exception localException)
    {
    }
  }

  public void checkScreen()
  {
    int i = new RqSP().getExitVal(this.context);
    String str1 = this.sp.getString("isLock", "0");
    String str2;
    if (!isTopActivity())
    {
      if (str1.equals("1"))
      {
        this.editor.putString("isLock", "0");
        this.editor.commit();
        str1 = "0";
      }
      onUnlock();
      Logger.i("tag", "activity不在");
      str2 = this.sp.getString("ScreenCmd", "2");
      this.sp.getString("LockTime", "2011-11-11 11:11:11");
      if ((!str2.equals("0")) || (i != 0))
        break label279;
      Logger.i("tj", "mKeyguardLock.disableKeyguard()");
      this.serverAppBean.mKeyguardLock.disableKeyguard();
      VolumeCtrl.silent(this.context);
      if (!"1".equals(str1))
        break label179;
      Logger.i("tag", "当前--已锁屏");
    }
    label179: 
    while (!str2.equals("2"))
    {
      do
      {
        return;
        onLock();
        break;
        if (!"0".equals(str1))
          break label270;
        Logger.i("tag", "当前--无锁屏");
      }
      while (((ActivityManager.RunningTaskInfo)((ActivityManager)this.context.getSystemService("activity")).getRunningTasks(1).get(0)).topActivity.getClassName().endsWith("com.appwoo.txtws.activity.EmergencyDialogActivity"));
      Intent localIntent2 = new Intent(this.context, ScreenOffActivity.class);
      localIntent2.setFlags(268435456);
      this.context.startActivity(localIntent2);
      return;
      Logger.i("tag", "0取值错误-1");
      return;
    }
    try
    {
      label270: label279: Logger.i("tj", "mKeyguardLock.reenableKeyguard()");
      this.serverAppBean.mKeyguardLock.reenableKeyguard();
      if (str1.equals("1"))
      {
        Intent localIntent1 = new Intent("closeScreenActivity");
        this.context.sendBroadcast(localIntent1);
        VolumeCtrl.ring(this.context);
        return;
      }
    }
    catch (Exception localException)
    {
      while (true)
      {
        localException.printStackTrace();
        continue;
        if (str1.equals("0"))
          Logger.i("tag", "2当前--无锁屏");
        else
          Logger.i("tag", "2取值错误-1");
      }
    }
  }

  public boolean checkSeniorTime(Context paramContext, String paramString1, String paramString2)
  {
    return new DBHelper(paramContext).getSeniorTimeCount(paramString1, paramString2) > 0;
  }

  public boolean checkSpecTime(Context paramContext, String paramString)
  {
    return new DBHelper(paramContext).getSpecialTimeCount(paramString) > 0;
  }

  public String getSrnCmd()
  {
    if (this.sp == null)
      this.sp = this.context.getSharedPreferences("ScreenLock", 0);
    return this.sp.getString("ScreenCmd", "2");
  }

  public void getTodayScreen()
  {
    String str1 = Global.getIMEI(this.context);
    try
    {
      StateBean localStateBean = this.loginService.isTodayScreenLock(str1, this.context);
      String str2 = Global.getDateAndTime(this.context);
      String str3 = localStateBean.getType();
      Logger.i("tag", "todayScreen:----" + str3 + "----\ntime:------" + str2);
      if (!str3.equals(""))
      {
        this.editor.putString("sttm", str2);
        this.editor.putString("todayScreen", str3);
        this.editor.commit();
        if (str3.equals("0"))
        {
          LockScreenCmd(str2);
          return;
        }
        UnlockScreenCmd(str2);
        return;
      }
    }
    catch (IOException localIOException)
    {
      localIOException.printStackTrace();
      return;
    }
    catch (XmlPullParserException localXmlPullParserException)
    {
      localXmlPullParserException.printStackTrace();
      return;
    }
    catch (TimeOutException localTimeOutException)
    {
      localTimeOutException.printStackTrace();
      return;
    }
    catch (NotFoundNetWorkException localNotFoundNetWorkException)
    {
      localNotFoundNetWorkException.printStackTrace();
    }
  }

  public void getTodayScreen(StateBean paramStateBean)
  {
    String str1 = Global.getDateAndTime(this.context);
    String str2 = null;
    if (paramStateBean != null)
    {
      str1 = paramStateBean.getScrSttm();
      str2 = paramStateBean.getScrType();
    }
    if ((str2 != null) && (!str2.equals("")))
    {
      this.editor.putString("sttm", str1);
      this.editor.putString("todayScreen", str2);
      this.editor.commit();
      Logger.i("bod", "todayScreen:----" + str2 + "----\ttime:------" + str1);
      if (str2.equals("0"))
        LockScreenCmd(str1);
    }
    else
    {
      return;
    }
    UnlockScreenCmd(str1);
  }

  public void onLock()
  {
    if (this.spl == null)
      this.spl = this.context.getSharedPreferences("ScreenLock", 0);
    if (this.editorl == null)
      this.editorl = this.spl.edit();
    this.editorl.putString("isLock", "1");
    this.editorl.commit();
    Logger.i("tag", "=rqlock==onLock");
  }

  public void onUnlock()
  {
    if (this.spl == null)
      this.spl = this.context.getSharedPreferences("ScreenLock", 0);
    if (this.editorl == null)
      this.editorl = this.spl.edit();
    this.editorl.putString("isLock", "0");
    this.editorl.commit();
    Logger.i("tag", "=rqlock==onUnlock");
  }

  public void screenIntime()
  {
    SharedPreferences localSharedPreferences1 = this.context.getSharedPreferences("timeconfig" + Global.getTodayDate(this.context), 0);
    SharedPreferences localSharedPreferences2 = this.context.getSharedPreferences("user_info", 0);
    long l1 = 1000L * (60L * Long.parseLong(localSharedPreferences1.getString("timelength", "1430")));
    long l2 = RQUrlPeroid.getDelay(this.context);
    long l3 = localSharedPreferences2.getLong("myusetime", 0L);
    new Date(l1 + Global.transDate(Global.getTodayDate(this.context)).getTime() + 1000L * l2);
    new Date(Global.transDateTime(Global.getTomorrow(this.context) + " 00:00:00").getTime());
    if (this.isSumTime)
    {
      Logger.d("bod", "进入时长设置--myusetime=" + l3 + "\ttimeLength=" + l1);
      if (1000L * (60L * l3) > l1)
      {
        this.editor.putBoolean("c1", true);
        this.editor.commit();
        Logger.d("bod", "进入时长设置--时长生效");
        return;
      }
      this.editor.putBoolean("c1", false);
      this.editor.commit();
      Logger.d("bod", "进入时长设置--时长未到");
      return;
    }
    this.editor.putBoolean("c1", false);
    this.editor.commit();
  }

  public void screenSeniorTime(int paramInt, boolean paramBoolean)
  {
    new RQUrlPeroid().bgRQMode(this.context);
    int i = Global.mode;
    boolean bool1 = checkSpecTime(this.context, Global.isBoarding);
    boolean bool2;
    if (bool1)
    {
      bool2 = true;
      if (i != 1)
        break label431;
      localDBHelper = new DBHelper(this.context);
      if (!bool2)
        break label342;
      Logger.d("bod", "高级启用。school -true。。特殊时间：" + bool1);
      if (!this.sp.getBoolean("c3", false))
      {
        WebTimeControlService.ut = 0L;
        this.editor.putBoolean("c3", true);
        this.editor.commit();
      }
      str2 = localDBHelper.getT1("1");
      if (paramBoolean)
        str2 = Global.getDateAndTime(this.context);
      if (Global.wayChange)
      {
        str2 = Global.getDateAndTime(this.context);
        Global.wayChange = false;
      }
      if ((Global.unLimitChange) && (Global.unLimit == 0))
      {
        str2 = Global.getDateAndTime(this.context);
        Global.unLimitChange = false;
        Logger.d("bod", "简单启用。home -。2unLimitChange变化222。[unlimite:" + Global.unLimit);
      }
      if (Global.way1 != 1)
        break label279;
      LockScreenCmd(str2);
      this.rnl.onNetCmd(str2);
    }
    label279: label342: 
    while (i != 0)
    {
      DBHelper localDBHelper;
      String str2;
      do
      {
        return;
        bool2 = checkSeniorTime(this.context, i, Global.isBoarding);
        break;
        if (Global.way1 == 0)
        {
          UnlockScreenCmd(str2);
          Logger.i("bod", "高级时间 断网1--");
          this.rnl.offNetCmd(str2);
          return;
        }
      }
      while (Global.way1 != 2);
      LockScreenCmd(str2);
      Logger.i("bod", "高级时间 断网2--");
      this.rnl.offNetCmd(str2);
      return;
      Logger.d("bod", "高级启用11。school -false。。");
      if (this.sp.getBoolean("c3", false))
      {
        WebTimeControlService.ut = 0L;
        this.editor.putBoolean("c3", false);
        this.editor.commit();
      }
      String str1 = localDBHelper.getT2();
      if (paramBoolean)
        str1 = Global.getDateAndTime(this.context);
      UnlockScreenCmd(str1);
      this.rnl.onNetCmd(str1);
      return;
    }
    label431: Logger.d("bod", "高级启用22。school -false。。");
    if (this.sp.getBoolean("c3", false))
    {
      WebTimeControlService.ut = 0L;
      this.editor.putBoolean("c3", false);
      this.editor.commit();
    }
    String str3 = new DBHelper(this.context).getT2();
    if (paramBoolean)
      str3 = Global.getDateAndTime(this.context);
    if (Global.way1 == 1)
      UnlockScreenCmd(str3);
    while (true)
    {
      screenSimpleTime(Global.way, paramBoolean);
      return;
      if (Global.way1 == 0)
      {
        this.rnl.onNetCmd(str3);
      }
      else if (Global.way1 == 2)
      {
        UnlockScreenCmd(str3);
        this.rnl.onNetCmd(str3);
      }
    }
  }

  public void screenSimpleTime(int paramInt, boolean paramBoolean)
  {
    int i = Global.way;
    new RQUrlPeroid().bgRQMode(this.context);
    int i1;
    int i3;
    if (Global.mode == 0)
    {
      Logger.i("bod", "进入简单时间规则");
      int j = Global.getDay(this.context);
      String str1 = Global.getDateAndTime(this.context).substring(11, 13);
      String str2 = Global.getDateAndTime(this.context).substring(14, 16);
      int k = Integer.parseInt(str1);
      int m = Integer.parseInt(str2);
      i1 = (m + k * 60) / 15;
      this.todayRule = this.webControlSP.getString(j, "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111");
      Logger.i("bod", "screen今天时间规则:" + this.todayRule + "\tindexInt=" + i1);
      int i2 = m - m % 15;
      new StringBuilder().append(i2).toString();
      if (i2 < 10)
        new StringBuilder("0").append(i2).toString();
      if (time == null)
        time = Global.getTodayDate(this.context) + " " + "00" + ":" + "00" + ":01";
      if (new Date(Global.transDate(time.split(" ")[0]).getTime()).before(new Date(1000L + Global.transDate(Global.getTodayDate(this.context)).getTime())))
        time = Global.getTodayDate(this.context) + " " + "00" + ":" + "00" + ":01";
      if (paramBoolean)
      {
        time = Global.getDateAndTime(this.context);
        Logger.d("bod", "简单启用。home -false。1简单时间规则变化111。");
      }
      if (Global.wayChange)
      {
        time = Global.getDateAndTime(this.context);
        Global.wayChange = false;
        Logger.d("bod", "简单启用。home -false。1waychange变化111。");
      }
      if ((Global.unLimitChange) && (Global.unLimit == 0))
      {
        time = Global.getDateAndTime(this.context);
        Global.unLimitChange = false;
        Logger.d("bod", "简单启用。home -。2unLimitChange变化222。[unlimite:" + Global.unLimit);
      }
      boolean bool = checkSpecTime(this.context, Global.isBoarding);
      if (!bool)
        break label622;
      i3 = 1;
      if (i3 == 0)
        break label711;
      if (!Boolean.valueOf(this.sp.getBoolean("c2", false)).booleanValue())
      {
        WebTimeControlService.ut = 0L;
        time = Global.getDateAndTime(this.context);
        this.editor.putBoolean("c2", true);
        this.editor.commit();
      }
      Logger.d("bod", "简单启用。home -true。。特殊时间：" + bool);
      if (i != 1)
        break label648;
      this.rnl.onNetCmd(time);
      LockScreenCmd(time);
    }
    label622: 
    do
    {
      return;
      if (this.todayRule.charAt(i1) == '0');
      for (i3 = 1; ; i3 = 0)
        break;
      if (i == 0)
      {
        this.rnl.offNetCmd(time);
        Logger.i("bod", "时间 断网1--");
        UnlockScreenCmd(time);
        return;
      }
    }
    while (i != 2);
    label648: LockScreenCmd(time);
    Logger.i("bod", "时间 断网2--");
    this.rnl.offNetCmd(time);
    return;
    label711: if (Boolean.valueOf(this.sp.getBoolean("c2", false)).booleanValue())
    {
      WebTimeControlService.ut = 0L;
      time = Global.getDateAndTime(this.context);
      Logger.d("bod", "简单启用。home -false。1111。--" + time);
      this.editor.putBoolean("c2", false);
      this.editor.commit();
    }
    Logger.d("bod", "简单启用。home -false。。");
    UnlockScreenCmd(time);
    this.rnl.onNetCmd(time);
  }

  public boolean t1BeforeT2(String paramString1, String paramString2, String paramString3)
  {
    Date localDate1 = Global.transDateTime(paramString1);
    Date localDate2 = Global.transDateTime(paramString2);
    String str = this.sp.getString("ScreenCmd", "2");
    boolean bool;
    if (localDate1.before(localDate2))
      bool = true;
    while (true)
    {
      Logger.d("bod", "屏幕==old cmd==" + str + "+\t==new cmd==" + paramString3 + "==比较时间，写入sp---isBefore--" + bool + "--\n--t1：" + paramString1 + "\tt2:" + paramString2);
      return bool;
      if (localDate1.equals(localDate2))
      {
        if (!str.equals(paramString3))
          bool = true;
        else
          bool = false;
      }
      else
        bool = false;
    }
  }
}

/* Location:           C:\Documents and Settings\Administrator\classes_dex2jar.jar
 * Qualified Name:     com.appwoo.txtws.service.RQScreenLock
 * JD-Core Version:    0.6.2
 */